# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=opencsg
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.4.2
pkgrel=1
pkgdesc="Library for image-based CSG rendering using OpenGL (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=("GPL2")
url="http://www.opencsg.org"
depends=("${MINGW_PACKAGE_PREFIX}-glew"
         # "${MINGW_PACKAGE_PREFIX}-freeglut" # need for building example
         )
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=(!strip staticlibs !buildflags)
source=("http://www.opencsg.org/OpenCSG-${pkgver}.tar.gz"
        01-makefile-mingw.patch
        02-qmake-mingw.patch)
sha256sums=('d952ec5d3a2e46a30019c210963fcddff66813efc9c29603b72f9553adff4afb'
            '18cf61241bd62140cd62a9a88e5d89c34035df731c384e8c78b480228be1e9fe'
            '87be0437e05a346e0bc082ad405c9ec9081f51bba03df8ec6c65ade7e934f99f')

prepare() {
  cd "${srcdir}/OpenCSG-${pkgver}"
  patch -p1 -i ${srcdir}/01-makefile-mingw.patch
  patch -p1 -i ${srcdir}/02-qmake-mingw.patch
}

build() {
  mv "${srcdir}/OpenCSG-${pkgver}" "${srcdir}/${MINGW_CHOST}"
  cd "${srcdir}/${MINGW_CHOST}"
  #rm -f example/Makefile src/Makefile
  #${MINGW_PREFIX}/bin/qmake -recursive opencsg.pro
  #make

  cd "${srcdir}/${MINGW_CHOST}/src"
  make all staticlib
}

package() {
  cd "${srcdir}/${MINGW_CHOST}/src"

  make prefix=${MINGW_PREFIX} INSTALL_ROOT=${pkgdir} install
  #install -D lib/libopencsg.so.$pkgver "${pkgdir}${MINGW_PREFIX}/lib/libopencsg.so.$pkgver"
  #install -D include/opencsg.h "${pkgdir}${MINGW_PREFIX}/include/opencsg.h"
}
